var time = "2021-5-16 9:14:30";
String.prototype.formaTime = function formaTime(template = `{0}年{1}月{2}日 {3}时{4}分{5}秒`){
  //this -> time时间字符串
  var arr = this.match(/\d+/g); //[“2021”, "5", ""]
  return template.replace(/{(\d+)}/g, function(_, index){
    var item = arr[index] || "00";
    item.length < 2 ? item = `0${item}` : null;
    return item;
  })
}

time = time.formaTime();
console.log(time);




